/*
   @Copyright:LibreOJ
   @Author:   tjyemail
   @Problem:  https://loj.ac/problem/119
   @Language: C++
   @Datetime: 20-08-13 15:07
   */
// dijkstra+heap, using forward star, time O(ElogV) 21ms

#include <bits/stdc++.h>
using namespace std;

#define VERTEX 2505
#define EDGE 6205
// linked forward star
struct Edge {
	int v, c, next;
	Edge(int v=0, int c=0, int next=-1):v(v), c(c), next(next){}
	bool operator<(const Edge &e) const { return c>e.c; } // mini-heap
} edges[EDGE*2];
int heads[VERTEX];
int ie = 0;
inline void add(int u, int v, int c) {
	edges[ie] = Edge(v, c, heads[u]);
	heads[u] = ie++;
}
//int path[VERTEX];

void dijkstra(int s, int t) {
	int c = 0;
	priority_queue<Edge> dists; // mini-heap
	for(dists.push({s, 0}); !dists.empty(); ) {
		s = dists.top().v, c = dists.top().c;
		dists.pop();
		if (s == t) break;
		// add edges from s's adjacency vertex
		for(int k=heads[s]; k!=-1; k=edges[k].next) {
			if (heads[edges[k].v]==-1) continue;
			dists.push({edges[k].v, c+edges[k].c});
			//path[edges[k].v] = s; // record path v <- s
		}
		heads[s] = -1;
	}
	printf("%d\n", c);
}

int main()
{
	int v, e, s, t, a, b, c; // vertex edge, start -> target
	scanf("%d %d %d %d", &v, &e, &s, &t);
	memset(heads, -1, sizeof(heads));
	for(; e--; ) {
		scanf("%d %d %d", &a, &b, &c); // a->b, cost
		add(a, b, c);
		add(b, a, c); // undirect graph
	}
	dijkstra(s, t);
	// shortest path t <- ... <- s
	//for(printf("%d", a); a!=s; printf("<-%d", a=path[a]));
	//printf("\n");
	return 0;
}
